package handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.apache.log4j.Logger;

public class RtmpOutHandler extends ChannelOutboundHandlerAdapter {
    private final static Logger logger = Logger.getLogger(RtmpOutHandler.class);
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
       // System.out.println(ctx + " === " + ctx.channel().unsafe().outboundBuffer().size());
//        logger.info(  "nioBufferSize == " +    ctx.channel().unsafe().outboundBuffer().nioBufferSize());
//        logger.info("ctx == " + ctx.channel().unsafe().outboundBuffer().size());

        if(ctx.channel().unsafe().outboundBuffer().size() > 10000){
            logger.info("ctx == " + ctx.channel().unsafe().outboundBuffer().size());
            ctx.close();
            return;
        }
        super.write(ctx, msg, promise);
    }
}
